package com.ruoyi.project.wx.api;


import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bootdo.R;
import com.ruoyi.project.wx.service.MemberCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 收藏
 */
@Controller
@RequestMapping("/api/memberCollect")
public class ApiMemberCollectController {

    @Autowired
    private MemberCollectService memberCollectService;

    /*收藏/取消收藏 商品店铺*/
    @ResponseBody
    @RequestMapping("/saveCollect")
    public R saveCollect(@RequestBody Map<String, Object> params) {
        if (!params.containsKey("userId") || StringUtils.isBlank(params.get("userId").toString())
                || !params.containsKey("collectId") || StringUtils.isBlank(params.get("collectId").toString())
                || !params.containsKey("status") || StringUtils.isBlank(params.get("status").toString())
        ) {
            return R.error("缺少参数");
        }
        try {
            return memberCollectService.saveCollect(params);
        } catch (Exception e) {
            return R.error("获取小类列表失败");
        }
    }

    /**
     *  收藏列表
     * @param params status 0 商品1商家
     * @return
     */
    @ResponseBody
    @RequestMapping("/getCollectList")
    public R getCollectList(@RequestBody Map<String, Object> params) {
        if (!params.containsKey("userId") || StringUtils.isBlank(params.get("userId").toString())
                ||!params.containsKey("status") || StringUtils.isBlank(params.get("status").toString())
        ) {
            return R.error("缺少参数");
        }
        try {
            return memberCollectService.getCollectList(params);
        } catch (Exception e) {
            return R.error("获取小类列表失败");
        }
    }
}
